####################
###  Figure 4    ###
####################
rm(list = ls());library(foreign)

install.packages("extrafont", dependencies=TRUE);library(extrafont)
install.packages("RColorBrewer", dependencies=TRUE);library(RColorBrewer)
gray<-"#d3d3d3";darkgray<-"#808080"


a<-c(.089582,     -.229496 ,   .40866)
b<-c( .280881,     -.033096,    .594859)
c<-c(.41303,      .108056,     .718004)
d<-c(.405453,     .093674,     .717232 )
e<-c(.545197,     .240293,    .850101  )

a1<-c(.089582,     -.178196,    .357361 )
b1<-c(.280881,     .017383,     .54438 )
c1<-c(.41303,      .157088,     .668972  )
d1<-c(.405453,     .1438,       .667106)
e1<-c( .545197,     .289314,     .801081 )

ese<-seq(e[2],e[3],length.out=5)
n.ahead<-seq(1,5,by=1)

layout(matrix(c(1,2), nrow=2, byrow=TRUE), heights=c(4, 1))
par(mai=c(0.20,0.20,0.2,0.1),family="Palatino",oma=c(2,2,2,2),mgp=c(2, 0.5, 0),cex.lab=1.2,cex.axis=.8)
plot(n.ahead, ese,type="n",main="Twitter Effect on US Behavior Toward the Rebels",lwd=4,col="black",ylab=expression(bold(US)~bold(to)~bold(Rebels)),pch=19,ylim=c(min(a),e[3]),xlim=c(1,5),xaxt='n',xlab=expression(bold(Twitter)))
abline(h=0,col="black",lwd=1,lty=3)
axis(1,at=c(1,2,3,4,5), labels=c("Total","International Support","Battlefield Success","Denounce Government","Clarify Aims") )

points(n.ahead[1], e1[2],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead[1], e1[3],lwd=3,pch=25, col=gray,lty=3)
segments(x0=n.ahead[1], y0=e1[2],x1=n.ahead[1], y1=e1[3],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[1], e[2],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[1], e[3],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[1], y0=e[2],x1=n.ahead[1], y1=e[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[1], e[1],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[2], a1[2],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead[2], a1[3],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead[2], y0=a1[2],x1=n.ahead[2], y1=a1[3],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[2], a[2],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[2], a[3],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[2], y0=a[2],x1=n.ahead[2], y1=a[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[2], a[1],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[3], b1[2],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead[3], b1[3],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead[3], y0=b1[2],x1=n.ahead[3], y1=b1[3],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[3], b[2],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[3], b[3],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[3], y0=b[2],x1=n.ahead[3], y1=b[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[3], b[1],lwd=3,pch=19, col= "black",lty=3)


points(n.ahead[4],  c1[2],lwd=3,pch= 24 , col=gray,lty=3)
points(n.ahead[4], c1[3],lwd=3,pch=25, col=gray,lty=3)
segments(x0=n.ahead[4], y0=c1[2],x1=n.ahead[4], y1=c1[3],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[4],  c[2],lwd=3,pch= 24 , col=darkgray,lty=3)
points(n.ahead[4], c[3],lwd=3,pch=25, col=darkgray,lty=3)
segments(x0=n.ahead[4], y0=c[2],x1=n.ahead[4], y1=c[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[4], c[1],lwd=3,pch=19, col= "black",lty=3)


points(n.ahead[5],  d1[2],lwd=3,pch= 24 , col=gray,lty=3)
points(n.ahead[5], d1[3],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead[5], y0=d1[2],x1=n.ahead[5], y1=d1[3],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[5],  d[2],lwd=3,pch= 24 , col=darkgray,lty=3)
points(n.ahead[5], d[3],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[5], y0=d[2],x1=n.ahead[5], y1=d[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[5], d[1],lwd=3,pch=19, col= "black",lty=3)

plot.new()
legend(x="center",title="",horiz=TRUE,legend=c("IRF","95% C.I.","90% C.I."),box.col="darkgray", col=c("black",darkgray, gray), pch=c(19,25,25),lwd=c(2,3,2))

####################
###  Figure 5    ###
####################

rm(list = ls());library(foreign)

install.packages("extrafont", dependencies=TRUE);library(extrafont)
install.packages("RColorBrewer", dependencies=TRUE);library(RColorBrewer)
gray<-"#d3d3d3";darkgray<-"#808080"


a<-c( .093297,     -.221707,    .4083 )
b<- c(.32519,      .01322,      .637159  )
c<-c(.404756,     .100305,     .709206)  
d<-c(.37593,.0648,.68706 ) 
e<-c(.544825,     .240871,     .848779  ) 


a1<-c( .093297,     -.171063,    .357656 )
b1<- c(  .32519,      .063377,     .587003  )
c1<-c(.404756,     .149253,     .660259)   
d1<-c(.373054,.113644,.632464) 
e1<-c(.544825,     .289739,     .799912)

ese<-seq(e[2],e[3],length.out=5)
n.ahead<-seq(1,5,by=1)
layout(matrix(c(1,2), nrow=2, byrow=TRUE), heights=c(4, 1))
par(mai=c(0.20,0.20,0.2,0.1),family="Palatino",oma=c(2,2,2,2),mgp=c(2, 0.5, 0),cex.lab=1.2,cex.axis=.8)

plot(n.ahead, ese,type="n",main="Twitter Effect on US Behavior Toward the Rebels",lwd=4,col="black",ylab=expression(bold(US)~bold(to)~bold(Rebels)),pch=19,ylim=c(-0.41,e[3]),xlim=c(1,5),xaxt='n',xlab=expression(bold(Twitter)))
abline(h=0,col="black",lwd=1,lty=3)


axis(1,at=c(1,2,3,4,5), labels=c("Total","International Support","Battlefield Success","Denounce Government","Clarify Aims") )
points(n.ahead[1], e1[2],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead[1], e1[3],lwd=3,pch=25, col=gray,lty=3)
segments(x0=n.ahead[1], y0=e1[2],x1=n.ahead[1], y1=e1[3],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[1], e[2],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[1], e[3],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[1], y0=e[2],x1=n.ahead[1], y1=e[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[1], e[1],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[2], a1[2],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead[2], a1[3],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead[2], y0=a1[2],x1=n.ahead[2], y1=a1[2],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[2], a[2],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[2], a[3],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[2], y0=a[2],x1=n.ahead[2], y1=a[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[2], a[1],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[3], b1[2],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead[3], b1[3],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead[3], y0=b1[2],x1=n.ahead[3], y1=b1[3],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[3], b[2],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[3], b[3],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[3], y0=b[2],x1=n.ahead[3], y1=b[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[3], b[1],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[4],  c1[2],lwd=3,pch= 24 , col=gray,lty=3)
points(n.ahead[4], c1[3],lwd=3,pch=25, col=gray,lty=3)
segments(x0=n.ahead[4], y0=c1[2],x1=n.ahead[4], y1=c1[3],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[4],  c[2],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[4], c[3],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[4], y0=c[2],x1=n.ahead[4], y1=c[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[4], c[1],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[5],  d1[2],lwd=3,pch= 24 , col=gray,lty=3)
points(n.ahead[5], d1[3],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead[5], y0=d1[2],x1=n.ahead[5], y1=d1[3],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[5],  d[2],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[5], d[3],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[5], y0=d[2],x1=n.ahead[5], y1=d[3],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[5], d[1],lwd=3,pch=19, col= "black",lty=3)

plot.new()
legend(x="center",title="",horiz=TRUE,legend=c("IRF","95% C.I.","90% C.I."),box.col="darkgray", col=c("black",darkgray, gray), pch=c(19,25,25),lwd=c(2,3,2))





